import React, { Component } from 'react';
import { createPortal } from 'react-dom';
import ReactEcharts from 'echarts-for-react';
import darkEchartsTheme from '../../config/theme/darkEchartsTheme';
import echarts from 'echarts';

const modalRoot = document.getElementById('dialog-root');

class WorldCsjGdpBarChart extends Component {
  constructor(props) {
    super(props);
    this.el = document.createElement('WorldCsjGdpBarChart');
    this.state = {
      chartOption: undefined,
      chartHeight: 270,
    };
  }
  componentDidMount() {
    modalRoot.appendChild(this.el);
    echarts.registerTheme('theme_name', darkEchartsTheme);
    this.setChartData();
  }

  setChartData() {
    const dataSource = [
      [14516, '长三角城市群'],
      [35342, '英国城市群'],
      [43857, '日本大都市圈'],
      [49565, '欧洲大都市圈'],
      [68462, '大西洋城市群'],
      [74200, '五大湖城市群']
    ];
    const option = {
      tooltip: {
        show: false,
        trigger: 'item',
        formatter: '{b} : {c}',
      },
      grid: {
        top: '8%',
        left: '0%',
        right: '3%',
        bottom: '3%',
        containLabel: true,
      },
      xAxis: {
          data: ['五大湖\n城市群', '大西洋\n城市群', '欧洲\n大都市圈', '日本\n大都市圈', '英国\n城市群', '长三角\n城市群'],
          axisLine: {
              lineStyle: {
                  color: '#0177d4'
              }
          },
          splitLine: {
            show:false
        },
          axisLabel: {
            color: function (value, index) {
              return value == '长三角城市群' ? '#00feff' : '#fff';
            },
              interval:0,
              fontSize: 11,
              rotate:40

          }
      },
      yAxis: {
          // name: "（美元）",
          nameTextStyle: {
              color: '#fff',
              fontSize: 12
          },
          axisLine: {
              lineStyle: {
                  color: '#0177d4'
              }
          },
          axisLabel: {
              color: '#fff',
              fontSize: 10,
          },
          splitLine: {
              show:false,
              lineStyle: {
                  color: '#0177d4'
              }
          },
          max:75000

      },
      series: [{
          type: 'bar',
          barWidth: 10,
          barGap: '10%',
          barCategoryGap: '10%',
          itemStyle:{
              normal:{
                barBorderRadius: 18,
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 1,
                    color: '#0286ff',
                  },
                  {
                    offset: 0.5,
                    color: '#027eff',
                  },
                  {
                    offset: 0,
                    color: '#00feff',
                  },
                ]),
              }
          },
          label: {
            normal: {
              show: true,
              position: 'top',
              textStyle: {
                color: '#fff',
                fontSize: 12,
              },
            },
          },
          data: [74200, 68462, 49565, 43857, 35342, 14516]
      }]
  };
    this.setState({ chartOption: option });
  }

  render() {
    const { style, width, height } = this.props;
    const dtTitle = `城市群人均GDP（单位：美元）`;
    const { chartOption } = this.state;
    return createPortal(
      <div
        style={{
          ...style,
          display: 'flex',
          flexDirection: 'column',
          width: width,
          height: height,
          color: '#fff',
          backgroundColor: 'rgba(0,0,0,0.6)',
          boxShadow: '0 1px 2px rgba(0,0,0,0.16), 0 1px 2px rgba(0,0,0,0.23)',
        }}
      >
        <div
          style={{
            lineHeight: '35px',
            height: 35,
            borderBottom: '1px solid rgb(238, 238, 238,0.2)',
            textAlign: 'center',
            fontWeight: 'bold'
          }}
        >
          <div style={{ float: 'left', marginLeft: 6, fontSize: 15 }}><div style={{ float: 'left', width: 5, height: 35, marginRight: 10, backgroundColor: 'rgba(63,177,277,1)', }} />{dtTitle}</div>
          <div style={{ float: 'right', marginRight: 8 }}>
          </div>
        </div>
        <div style={{ margin: '3px 3px 3px 3px' }}>
          <div>
            {chartOption !== undefined && (
              <ReactEcharts
                option={chartOption}
                notMerge={true}
                lazyUpdate={true}
                theme={'theme_name'}
                style={{ height: this.state.chartHeight }}
              />
            )}
          </div>
        </div>
      </div>,
      this.el
    );
  }
}

export default WorldCsjGdpBarChart;
